<% layout('/layouts/default.html', {title: '会员管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i>${text('会员管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('vip:member:edit')){ %>
				<a href="${ctx}/vip/member/form" class="btn btn-default btnTool" title="${text('新增会员')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${member}" action="${ctx}/vip/member/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('会员姓名')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="32" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('手机号')}：</label>
					<div class="control-inline">
						<#form:input path="mobile" maxlength="11" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-sm4">${text('代理')}：</label>
					<div class="control-inline" style="width: 100px;">
						<#form:select path="agentId" items="${agentList}" itemLabel="user_name" itemValue="user_code" blankOption="true" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('状态')}：</label>
					<div class="control-inline width-90">
						<#form:select path="status" dictType="sys_user_status" blankOption="true" blankOptionLabel="全部" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<div class="box-title" id="countTitle" style="padding:4px;text-align:center;font-size:20px;">
			</div>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text('会员姓名')}', name:'name', index:'a.name', width:150, align:"center", frozen:true, formatter: function(val, obj, row, act){
                return '<a href="${ctx}/vip/record/memberPersonRecord?memberId='+row.id+'" class="btnList" data-title="${text('会员报表记录')}">'+(val||row.id)+'</a>';
            }},
            {header:'${text('手机号')}', name:'mobile', index:'a.mobile', width:150, align:"center"},
            {header:'${text('微信号')}', name:'wechat', index:'a.wechat', width:150, align:"center"},
            {header:'${text('所属代理')}', name:'user.userName', index:'u.user_name', width:150, align:"center"},
            {header:'${text('余额')}', name:'balance', index:'a.balance', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
            {header:'${text('积分')}', name:'points', index:'a.points', width:150, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
            {header:'${text('结账金额')}', name:'balance', index:'a.balance', width:120, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
            {header:'${text('总出货')}', name:'outTotal', index:'a.outTotal', width:120, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('总入货')}', name:'inTotal', index:'a.inTotal', width:120, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('总充值')}', name:'rechargeTotal', index:'a.recharge_total', width:120, align:"center", formatter: function(val, obj, row, act){
                return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
            }},
            {header:'${text('总支出')}', name:'payTotal', index:'a.pay_total', width:120, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('状态')}', name:'status', index:'a.status', width:120, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sys_status')}, val, '未知', true);
                }},
            {header:'${text('创建时间')}', name:'createDate', index:'a.create_date', width:150, align:"center"},
            {header:'${text('操作')}', name:'actions', width:150, sortable:false, title:false, formatter: function(val, obj, row, act){
                var actions = [];
            <% if(hasPermi('vip:member:edit')){ %>
                    actions.push('<a href="${ctx}/vip/member/form?id='+row.id+'" class="btnList" title="${text('编辑会员')}"><i class="fa fa-pencil"></i></a>&nbsp;');
                    if (row.status == Global.STATUS_NORMAL){
                          actions.push('<a href="${ctx}/vip/member/disable?id='+row.id+'" class="btnList" title="${text('停用会员')}" data-confirm="${text('确认要停用该会员吗？')}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
                    }
                    if (row.status == Global.STATUS_DISABLE){
                          actions.push('<a href="${ctx}/vip/member/enable?id='+row.id+'" class="btnList" title="${text('启用会员')}" data-confirm="${text('确认要启用该会员吗？')}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
                    }
            <% } %>
            <% if(hasPermi('vip:member:del')){ %>
                    if (row.status == Global.STATUS_DISABLE){
                        actions.push('<a href="${ctx}/vip/member/delete?id='+row.id+'" class="btnList" title="${text('删除会员')}" data-confirm="${text('确认要删除该会员吗？')}"><i class="fa fa-trash-o"></i></a>&nbsp;');
                    }
            <% } %>
            <% if(hasPermi('vip:member:edit')){ %>
                   actions.push('<a href="javascript:" class="btnMore" title="${text('更多操作')}"><i class="fa fa-chevron-circle-right"></i></a>&nbsp;');
                   actions.push('<div class="moreItems">');
                   actions.push('<a href="${ctx}/vip/record/goods?type=1&&userId='+row.id+'" class="btn btn-default btn-xs btnList" title="${text('出货')}"><i class="fa fa-check-square-o"></i> ${text('出货')}</a>&nbsp;');
                   actions.push('<a href="${ctx}/vip/record/goods?type=2&&userId='+row.id+'" class="btn btn-default btn-xs btnList" title="${text('入货')}"><i class="fa fa-check-circle-o"></i> ${text('入货')}</a>&nbsp;');
                   actions.push('<a href="${ctx}/vip/record/goods?type=3&&userId='+row.id+'" class="btn btn-default btn-xs btnList" title="${text('结账')}"><i class="fa fa-check-circle-o"></i> ${text('结账')}</a>&nbsp;');
                   actions.push('<a href="${ctx}/vip/record/goods?type=4&&userId='+row.id+'" class="btn btn-default btn-xs btnList" title="${text('充值')}"><i class="fa fa-check-circle-o"></i> ${text('充值')}</a>&nbsp;');
            <% } %>
                return actions.join('');
            }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){
            buildCount(data.otherData);
        }
    });

    //统计数据标题
    function buildCount(countData){
        if(countData == undefined){
            $('#countTitle').html("统计数据为空");
            return;
        }
        var inTotalTitle ="积分正:"+formatNumber(countData.plusPoints)+"&nbsp&nbsp&nbsp";
        var outTotalTitle ="积分负:"+formatNumber(countData.minusPoints)+"&nbsp&nbsp&nbsp";
        var pointsTitle ="总积分:"+formatNumber(countData.balance)+"&nbsp&nbsp&nbsp";
        var rechargeTitle ="总充值:"+formatNumber(countData.rechargeTotal)+"&nbsp&nbsp&nbsp";
        var payTitle = "总支出:"+formatNumber(countData.payTotal)+"&nbsp&nbsp&nbsp";
        $('#countTitle').html(inTotalTitle + outTotalTitle + pointsTitle + rechargeTitle + payTitle);
    }
</script>
